package app.models.game;

import app.dtos.WeekInfo;
import com.github.sog.annotation.TableBind;
import com.github.sog.plugin.sqlinxml.SqlKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;

import java.util.List;

/**
 * <p>
 * .
 * </p>
 *
 * @author Jerry Ou
 * @version 1.0 2014-02-12 13:41
 * @since JDK 1.6
 */
@TableBind(tableName = "ol_sign_log")
public class SignLog extends Model<SignLog> {

    private static final long   serialVersionUID = 1L;
    /**
     * The public dao.
     */
    public static final SignLog dao = new SignLog();


    public List<SignLog> list(){
        return find(SqlKit.sql("signlog.list"));
    }

    public void processWeekInfos(List<WeekInfo> weekInfos, WeekInfo today, long mid) {
        String todayYmd = today.dayYmd;
        for (WeekInfo info : weekInfos) {
            String day = info.getDayYmd();
            SignLog signLog = findByDay(day, mid);

            if (signLog == null) {
                info.sign = false;
            } else {
                info.sign = true;
            }

            if (day.equals(todayYmd)) {
                today.sign = info.sign;
                break;
            }
        }
    }

    public SignLog findByDay(String day, long mid) {
        return findFirst(SqlKit.sql("signlog.findByDay"), day, mid);
    }

    public long balCount(WeekInfo start, WeekInfo end, long mid) {
        return Db.queryLong(SqlKit.sql("signlog.balCount"), start.dayYmd, end.dayYmd, mid);
    }
}